package sg.edu.nus.iss.team8s.vmcs.beans;
/**
 * 
 * @author Nie XiaoYi
 *
 */
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;

public class Environment {

	private Hashtable<String, String> ht;
	
	private final String FILENAME = "Environment.txt";
	private static String sWorkPath="";
	private static String sWorkFolder = "/data/";
	private String cashKey = "CashPropFile";
	private String drinkKey = "DrinkPropFile";
	
	public void initialize() throws IOException{
		if(ht == null)
			ht = new Hashtable<String, String>();
		
		String appPath = getClass().getResource(sWorkFolder).getPath();
		sWorkPath = java.net.URLDecoder.decode(appPath, "UTF-8") ; 
	
		if (sWorkPath.startsWith("/")){
		sWorkPath=sWorkPath.substring(1);}
		
		File file = new File(sWorkPath + FILENAME);
		FileReader reader = new FileReader(file);
		BufferedReader in = new BufferedReader(reader);
		String lineStr;
		while((lineStr = in.readLine()) != null){
			String[] str = lineStr.split(",");
			ht.put(str[0], str[1]);
		}
	}
	
	public String getCashPropFile(){
		if(ht.isEmpty() && !ht.containsKey(cashKey))
			return null;
		return (String)ht.get(cashKey);
	}
	
	public String getDrinkPropFile(){
		if(ht.isEmpty() && !ht.containsKey(drinkKey))
			return null;
		return (String)ht.get(drinkKey);
	}
}
